home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / dirparse.zip / DIRPARS2.PAS < prev    next >
Pascal/Delphi Source File  |  1991-10-22  |  3KB  |  99 lines

  1. Program Dir_Parser;        (* Hi, STIPE wanted something to do this *)
  2.                            (* Took 5 minutes.... *)
  3.  
  4. (*$M 2048, 0, 0 *)         (* 2K stack, Min Heap 0, Max Heap 0 *)
  5. Uses Dos, Crt;             (* Use DOS allows use of FINDFIRST and FINDNEXT *)
  6.  
  7. Var
  8.    Temp,
  9.    Lines,
  10.    Index: Byte;
  11.  
  12. Const
  13.      ColorArray: Array[0..5] of Byte = (11,9,15,13,14,10);
  14.  
  15. Procedure Chk_Pause;
  16. Var
  17.    Ch: Char;
  18. Const
  19.      Lines: Word = 1;
  20. Begin
  21.  Inc(Lines);
  22.  If (Lines mod 18) = 0 then
  23.    Begin
  24.     Write('<<MORE>>');
  25.     Inc(Lines);
  26.     Ch:= ReadKey;
  27.     GotoXY(Wherex-9, Wherey);
  28.     Writeln;
  29.    End;
  30. End;
  31.  
  32. Procedure Parse(Param: String);  (* Pass Name of extension to routine *)
  33. Var
  34.    Info: SearchRec;              (* SearchRec - Info that DOS returns *)
  35.    Temp,                         (* Used for Speed - No need to re-evaluate *)
  36.                                  (* The LENGTH every time in the For Loop *)
  37.    Index,
  38.    Counter: Byte;                  (* Index in For Loop *)
  39.  
  40. Begin
  41.  Counter:=0;
  42.  FindFirst(Param, AnyFile, Info);  (* Find First Matching FileName *)
  43.  If (DosError = 18) then                (* Any at All? *)
  44.    Begin
  45.     Temp:= Length(Param);               (* Nope, convert extension to Upper *)
  46.     For Index:=1 to Temp do             (* Case so it looks nice *)
  47.       Param[Index]:= Upcase(Param[Index]);
  48.     Writeln(' No Files of type ',Param,' found.'+#10#13);
  49.     Chk_Pause;
  50.    End;
  51.  While (DosError = 0) do               (* Keep chuggin' so long as ther are *)
  52.    Begin
  53.     Inc(Counter);                      (* Files to be printed *)
  54.     Write(Info.Name:15);
  55.     FindNext(Info);
  56.     If ((Counter mod 5) = 0) then
  57.       Begin
  58.        Writeln;
  59.        Chk_Pause;
  60.       End;
  61.    End;
  62.  
  63. If ((Counter mod 5) <> 0) then
  64.   Begin
  65.    Writeln;
  66.    Chk_Pause;
  67.   End;
  68. If (Counter > 0) then
  69.   Begin
  70.    Writeln(' Files of this type: ',Counter,+#10#13);
  71.    Chk_Pause;
  72.   End;
  73. End;
  74.  
  75.  
  76. Begin
  77.  If (ParamCount >= 1) Then      (* Check to see if any command line params *)
  78.    Begin                        (* Were Specified.  If not, give help *)
  79.     TextBackGround(Blue);
  80.     ClrScr;
  81.     Temp:= ParamCount;
  82.     For Index:=1 to Temp do     (* If So, print all files w/given Extension *)
  83.      Begin
  84.       TextColor(ColorArray[Index mod 6]);
  85.       Parse(ParamStr(Index));
  86.      End
  87.    End
  88.  Else
  89.    Begin
  90.     TextBackGround(Blue);
  91.     TextColor(Yellow);
  92.     ClrScr;
  93.     Writeln('Dir-Parse: (c) 1991 GHT, Ltd.'+#10#13+
  94.     'USAGE: DIRPARSE <spec> <spec> <spec>'+#10#13+
  95.     'Where <spec> is the specs for the files to scan for'+#10#13+
  96.     'IE - DIRPARS2 *.PAS QM*.EXE FA*.??L'+#10#13+
  97.     'Handy to have .BAT file with commonly used extensions.');
  98.    End;
  99. End.